package commons

import (
	"image"
	"image/draw"
)

func Jpeg2RGBA(img image.Image) *image.RGBA {
	tmp := image.NewRGBA(img.Bounds())
	draw.Draw(tmp, img.Bounds(), img, img.Bounds().Min, draw.Src)
	return tmp
}

func Png2jpg(img image.Image) image.Image {
	imgRect := image.Rect(0, 0, img.Bounds().Max.X, img.Bounds().Max.Y)
	jpg := image.NewRGBA(imgRect)

	// 使用无背景色
	draw.Draw(jpg, jpg.Bounds(), img, img.Bounds().Min, draw.Src)
	// draw.Draw(jpg, jpg.Bounds(), &image.Uniform{bgColor}, image.Point{}, draw.Src)

	// paste image OVER to newImage
	draw.Draw(jpg, jpg.Bounds(), img, img.Bounds().Min, draw.Over)
	return jpg
}
